package com.deve.pig.service.merchant.impl;

import com.deve.pig.common.BusinessData;
import com.deve.pig.mapper.MerchantImagesMapper;
import com.deve.pig.model.MerchantImages;
import com.deve.pig.model.MerchantImagesExample.Criteria;
import com.deve.pig.model.MerchantImagesExample;
import com.deve.pig.service.merchant.IMerchantImagesService;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import my.utils.Pagination;
import org.springframework.stereotype.Service;

@Service("merchantImagesService")
public class MerchantImagesServiceImpl extends BusinessData implements IMerchantImagesService {
    @Resource
    private MerchantImagesMapper merchantImagesMapper;

    @Override
    public int add(MerchantImages entity) {
        return merchantImagesMapper.insert(entity);
    }

    @Override
    public int delete(MerchantImagesExample example) {
        return merchantImagesMapper.deleteByExample(example);
    }

    @Override
    public int delete(int id) {
        return merchantImagesMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MerchantImages entity) {
        return merchantImagesMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public int updateByExampleSelective(MerchantImages record, MerchantImagesExample example) {
        return merchantImagesMapper.updateByExampleSelective(record, example);
    }

    @Override
    public Pagination findPagination(Map<String, Object> queryMap, int currentPage, int pageSize) {
        MerchantImagesExample merchantImagesExample = new MerchantImagesExample();
        merchantImagesExample.setOrderByClause("id desc");
        merchantImagesExample.createCriteria().andMerchantIdEqualTo(Integer.parseInt((String) queryMap.get("merchantId")));
        // 设置分页参数
        merchantImagesExample.setPageSize(pageSize);
        merchantImagesExample.setStartIndex((currentPage - 1) * pageSize);
        List<MerchantImages> items = merchantImagesMapper.selectByExample(merchantImagesExample);
        int totalCount = (int) merchantImagesMapper.countByExample(merchantImagesExample);
        return new Pagination(pageSize, currentPage, totalCount, items);
    }

    @Override
    public MerchantImages findById(int id) {
        return merchantImagesMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MerchantImages> findAll() {
        return merchantImagesMapper.selectByExample(null);
    }

    @Override
    public List<MerchantImages> findByCriteria(MerchantImagesExample criteria) {
        return merchantImagesMapper.selectByExample(criteria);
    }

    @Override
    @SuppressWarnings("unchecked")
    public LinkedHashMap<String, List> getExportData() {
        LinkedHashMap<String, List> map = new LinkedHashMap<String, List>();
        map.put("SheetName_1", findAll());
        map.put("SheetName_2", findAll());
        map.put("SheetName_3", findAll());
        map.put("SheetName_N", findAll());
        return map;
    }

    @Override
    public int countByExample(MerchantImagesExample example) {
        return merchantImagesMapper.countByExample(example);
    }
}